//先导入pako
import pako from 'pako'
// b64Data-->传入加密的数据进行解密
function unzip(b64Data) {
	var strData = atob(b64Data)
	// Convert binary string to character-number array
	var charData = strData.split('').map(function(x) {
		return x.charCodeAt(0)
	})
	// Turn number array into byte-array
	var binData = new Uint8Array(charData)
	// // unzip
	var data = pako.inflate(binData)
	// Convert gunzipped byteArray back to ascii string:
	strData = decodeUtf8(new Uint8Array(data));
	return strData
}

function decodeUtf8(bytes) {
	var encoded = "";
	for (var i = 0; i < bytes.length; i++) {
		encoded += '%' + bytes[i].toString(16);
	}
	return decodeURIComponent(encoded);
}
// 加密
function zip(str) {
	var binaryString = pako.gzip(str, {
		to: 'string'
	})
	return btoa(binaryString)
}


const host = "https://fcc.sdyilian.top/api/";


const API = {
	login: host + "login/login",
	news_reveal: host + "index/news_reveal",
	carousel: host + "index/carousel",
	getList: host + "properties/getList",
	adviser_list:host+"properties/adviser_list",
	info:host+"properties/info",
	list:host+"properties/list",
	unittype_list:host+"properties/unittype_list",
	unit_list:host+"properties/unit_list",
	room_list:host+"properties/room_list",
	evidence_collection:host+"evidence/evidence_collection",
	informationGetList:host+"information/getList",
	schoolDistrict:host+"schoolDistrict/getList",
	room_vr:host+"properties/room_vr",
	comment_list:host+"properties/comment_list",
	comment_save:host+"properties/comment_save"
}
const HTTPREQUEST = function(url, method, data, success, fail, type, status) {
	let authorVal = ''
	uni.request({
		url: url,
		data: data,
		method: method,
		header: {
			"Authorization": 'Bearer 2df9780712148f04edfc468b1912110b'
		},
		success: (res) => {
			try {
				if (res.data.code == 1) {
					success(res.data);
				} else {
					fail(res.data.msg);
				}

			} catch (e) {
				console.log("错误信息的res", res);
				console.log(e);
			}
		},
		fail: (res) => {
			console.log("res==", res);
			fail(res);
		}
	})
}


export default {
	API,
	HTTPREQUEST,
}